package com.ccl.iot;import com.ccl.iot.IOTInterface.IOTStateMonitorInterface;
import com.ccl.iot.IOTInterface.IOTStateMonitorInterface.IOTStateChangeListener;

public class IOTStateMonitor extends IOTMonitor<IOTStateChangeListener> implements IOTStateMonitorInterface {
	private IOTStateMonitorInterface iSource = this;

	public IOTStateMonitor(){
		
	}

	public IOTStateMonitor(IOTStateMonitorInterface aSource){
		if (aSource != null){
			iSource = aSource;
		}
	}
	
	@Override
	public boolean addStateChangeListener(IOTStateChangeListener aListener) {
		return super.addMonitorListener(aListener);
	}

	@Override
	public boolean removeStateChangeListener(IOTStateChangeListener aListener) {
		return super.removeMonitorListener(aListener);
	}

	public void onStatusChange(int aState){
		int tIndex = 0;
		IOTStateChangeListener tListener;
		
		while((tListener = super.getMonitorListener(tIndex++)) != null){
			tListener.onStateChanged(iSource, aState);
		}
	}
}
